const { Sequelize } = require('sequelize');
const ErrorModel = require('./define/ErrorModel');

module.exports = function sequelize(options) {
	const { storage, namespace = '' } = options;

	const sequelize = new Sequelize({
		dialect: 'sqlite',
		storage,
		define: {
			underscored: true,
			timestamps: false,
			freezeTableName: true
		},
		logging: () => { }
	});

	[ErrorModel].forEach(item => {
		item(sequelize, namespace);
	});

	const Model = {
		ErrorModel: sequelize.model('ErrorModel')
	};

	return [sequelize, Model];
};